/*** Class Name: iFulfillAssignPriorityIndex
 * Author: Accenture
 * Date: 13-Jun-2011
 * Requirement/Project Name: iFulfill
 * Requirement Description: Updates the Priority Index Lookup field on FI based on the product Family.
                            Invoked on insert/update of FI - (FulfillmentItemTrigger) 
 **/
 
public with sharing class iFulfillAssignPriorityIndex{  
     
     /*
     * This method fetch priority index value based on the product family. 
     * checks the product family of the Fulfillment Item and priority index table product family ,
     * if both are same then populate the priority index value from the ifulfill Priority Index table.
     *
     */
     public static void AssignPriorityIndex(list<Fullfilment_Item__c> newFItems){
         Map<string,id> priorityMap = new Map<string,id>();          
          for(ifullfill_Priority_Index__c PI:[select Id,Name,Product_Family__c from ifullfill_Priority_Index__c]){
               priorityMap.put(PI.Product_Family__c,PI.Id);     
          }
          for(Fullfilment_Item__c FI:newFItems){
               if(priorityMap.containsKey(FI.Product_Family__c)){
                 FI.iFullfill_Priority_Index__c = priorityMap.get(FI.Product_Family__c); 
               }
          }
     }
     /*
     * This method fetch the Fulfillment period value based on the UDAC code.
     * Checks the Fulfillment UDAC code and fulfillment product UDAC code , 
     * if both are same then populate the fulfillment period value from the fulfillment product table.
     */
     public static void AssignPeriodValue(list<Fullfilment_Item__c> newFItems){
         Map<string,Decimal> periodMap= new Map<string,Decimal>();
         for(Fulfillment_Products__c FP:[select Product_UDAC_Code__c,Fulfillment_Period_Value__c from Fulfillment_Products__c where Status__c = 'Active']){
               periodMap.put(FP.Product_UDAC_Code__c,FP.Fulfillment_Period_Value__c);     
          }
          for(Fullfilment_Item__c FI:newFItems){
               if(periodMap.containsKey(FI.UDAC__c)){
                 FI.Fulfillment_Period_Value__c = periodMap.get(FI.UDAC__c); 
               }
          }

     }
    
}